package com.kingyea.mobilepolice.marketorg.controller;

import com.kingyea.mobilepolice.marketorg.bean.MarketOrg;
import com.kingyea.mobilepolice.marketorg.service.MarketOrgService;
import com.kingyea.mobilepolice.system.StateCode;
import com.kingyea.mobilepolice.util.ExceptionConditions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Mr.Lin
 * @version v1.0.0
 * @description MarketOrg 控制层
 * @date Created in 2018-04-26 15:22:49
 */
@RequestMapping(value = "/marketOrg")
@RestController
public class MarketOrgController {

    private static final Logger LOGGER = LoggerFactory.getLogger(MarketOrgController.class);

    @Autowired
    private MarketOrgService marketOrgService;

    /**
     * 查询全部
     *
     * @param
     * @return
     */
    @RequestMapping(method = RequestMethod.GET)
    public List<MarketOrg> list() {
        return marketOrgService.search(null);
    }

    /**
     * 创建
     *
     * @param marketOrg
     * @return
     */
    @RequestMapping(method = RequestMethod.POST)
    public Object create(@RequestBody MarketOrg marketOrg) {
        ExceptionConditions.checkStringNotEmpty(marketOrg.getOrgSerialNo(), StateCode.NO_ARGUMENT_ERROR);
        ExceptionConditions.checkNotNull(marketOrg.getMarketCode(), StateCode.NO_ARGUMENT_ERROR);
        return marketOrgService.save(marketOrg);
    }


    /**
     * 删除
     *
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    public Object delete(Integer marketCode) {
        return marketOrgService.deleteMarketCode(marketCode);
    }

}
